package com.study.pool;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class TestSchedule
{
    public static void main(String[] args)
    {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(Thread.currentThread().getName() + "--->" +sdf.format(new Date()));
        int i = Runtime.getRuntime().availableProcessors();
        System.out.println(i);
        ScheduledExecutorService pool = Executors.newScheduledThreadPool(i);
        pool.schedule(new Task(), 3, TimeUnit.SECONDS);
        pool.shutdown();
    }
}

class Task implements Runnable
{
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Override
    public void run()
    {
        System.out.println(Thread.currentThread().getName() + "--->" + sdf.format(new Date()));
    }
}
